package com.example.mhandler;

import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
import android.os.SystemClock;
import android.util.Log;

import static android.R.attr.y;

public class MyHandler {

    public  MyMessageQueue mQueue;

    public MyHandler()  {
        MyLooper looper=MyLooper.myLooper();

        mQueue=looper.mQueue;
    }

    public void handlerMessage(MyMessage message){

    };

    public void sendMessage(MyMessage message) {

        sendMessageDelayed(message,0);

    }


    public final boolean sendMessageDelayed(MyMessage msg, long delayMillis)
    {
        if (delayMillis < 0) {
            delayMillis = 0;
        }
       return sendMessageAtTime(msg, delayMillis);
    }

    public boolean sendMessageAtTime(MyMessage msg, long uptimeMillis) {
        MyMessageQueue queue = mQueue;
        if (queue == null) {
            RuntimeException e = new RuntimeException(
                    this + " sendMessageAtTime() called with no mQueue");
            Log.w("Looper", e.getMessage(), e);
            return false;
        }
        return enqueueMessage(queue, msg, uptimeMillis);
    }

    private boolean enqueueMessage(MyMessageQueue queue, MyMessage msg, long uptimeMillis) {
        msg.target = this;

        return queue.enqueueMessage(msg, uptimeMillis);
    }
}